package cn.principle.demeter;

import java.util.ArrayList;
import java.util.List;

//?????
public class Demeter1 {

	public static void main(String[] args) {
		//????????? SchoolManager ????
		SchoolManager schoolManager = new SchoolManager();
		//??????????id ??  ?У???????????
		schoolManager.printAllEmployee(new CollegeManager());

	}

}


//?У????????
class Employee {
	private String id;

	public void setId(String id) {
		this.id = id;
	}

	public String getId() {
		return id;
	}
}


//?????????
class CollegeEmployee {
	private String id;

	public void setId(String id) {
		this.id = id;
	}

	public String getId() {
		return id;
	}
}


//????????????????
class CollegeManager {
	//???????????????
	public List<CollegeEmployee> getAllEmployee() {
		List<CollegeEmployee> list = new ArrayList<CollegeEmployee>();
		for (int i = 0; i < 10; i++) { //??????????????10??????? list
			CollegeEmployee emp = new CollegeEmployee();
			emp.setId("?????id= " + i);
			list.add(emp);
		}
		return list;
	}
}

//?У??????

//???? SchoolManager ????????????????Щ Employee??CollegeManager
//CollegeEmployee ???? ??????? ????????????????Υ???? ????????? 
class SchoolManager {
	//?????У????????
	public List<Employee> getAllEmployee() {
		List<Employee> list = new ArrayList<Employee>();
		
		for (int i = 0; i < 5; i++) { //??????????????5??????? list
			Employee emp = new Employee();
			emp.setId("?У??????id= " + i);
			list.add(emp);
		}
		return list;
	}

	//?÷??????????У?????????????(id)
	void printAllEmployee(CollegeManager sub) {
		
		//????????
		//1. ????? CollegeEmployee ????  SchoolManager?????????
		//2. CollegeEmployee ??????????????????? SchoolManager
		//3. Υ???? ????????? 
		
		//??????????
		List<CollegeEmployee> list1 = sub.getAllEmployee();
		System.out.println("------------?????------------");
		for (CollegeEmployee e : list1) {
			System.out.println(e.getId());
		}
		//??????У??????
		List<Employee> list2 = this.getAllEmployee();
		System.out.println("------------?У??????------------");
		for (Employee e : list2) {
			System.out.println(e.getId());
		}
	}
}
